home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Original Shareware 1.1
/
The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso
/
38
/
sgn_bans.zip
/
BRESENHM.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1985-10-28
|
2KB
|
84 lines
{ BRESENHM.PAS ( note, not BresenhAm.Pas ) }
{ ~ }
{ Module is for use with Epson graphics package Printpak.Pas }
{ Bresenham's algorithm from drawing a pixel line }
{ Byte, Nov. 1985, pp 219-232 }
{ Pascal version by Prof. Richard Rasala, Northeastern U. }
Procedure Bresenham(x1,y1,x2,y2 : integer ) ;
Var
x ,y, z, a, b, dx, dy, d, deltap, deltaq : integer ;
begin
dx := abs(x2-x1) ;
dy := abs(y2-y1) ;
if dy <= dx then { slope <= 1 }
begin
x := x1 ; { initialize x }
y := y1 ; { initialize y }
z := x2 ; { set sentinel in x direction }
{ now set x-increment ...}
if x1 <= x2
then a := 1 { x increases }
else a := -1 ; { x decreases }
{ now set y increment ...}
if y1 <= y2
then b := 1 { y increases }
else b := -1 ; { y decreases }
{ initialize decision function d and its deltas }
{ note, u & v are Bresenham's own notation }
deltap := dy + dy ; { 2v }
d := deltap - dx ; { 2v - u is initial value of d }
deltaq := d - dx ; { 2v - 2u }
{ locate and plot points ...}
Pset(x,y,1) ; { first point }
while x <> z do
begin
x := x + a ; { always increment x }
if d < 0
then d := d + deltap { d = d + 2v }
else
begin
y := y + b ; { increment y also - i.e. go diagonal }
d := d + deltaq ; { d = d + 2v - 2u }
end ; { else }
Pset(x,y,1) ;
end ; { while }
end { case of dy <= dx }
else { dx <= dy so view x as a function of y }
begin
y := y1 ; { initialize y }
x := x1 ; { initialize x }
z := y2 ; { set sentinel in y direction }
{ now set y increment ...}
if y1 <= y2
then a := 1 { y increase }
else a := -1 ; { y decreases }
{ now set x increment }
if x1 <= x2
then b := 1 { x increase }
else b := -1 ; { x decreases }
{ initialize decision function and its deltas }
deltap := dx + dx ;
d := deltap - dy ;
deltaq := d - dy ;
{ locate and plot points }
Pset(x,y,1) ; { first point }
while y <> z do
begin
y := y + a ;
if d < 0
then d := d + deltap
else
begin
x := x + b ;
d := d + deltaq ;
end ; { else }
Pset(x,y,1) ;
end { while }
end { else }
end ; { Bresenham }